<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Vote
 * @copyright  Copyright KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 * @version    $Id: Controller.php 2011-03-09 08:45:41Z idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Vote
 * @copyright  Copyright KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 */

class Vote_Widget_ProfileVotingsController extends Engine_Content_Widget_Abstract
{
	protected $_childCount;

  public function indexAction()
  {
		$this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
		$this->view->subject = $subject = Engine_Api::_()->core()->getSubject('user');

    $this->view->isSelf = $viewer->isSelf($subject);

    if ($subject->getType() != 'user') {
      return $this->setNoRender();
    }

    $empty = true;
		$table = Engine_Api::_()->getDbTable('challenges', 'vote');
		$params = array(
      'approved' => 1,
      'user_id' => $subject->getIdentity(),
      'page' => $this->_getParam('page', 1)
    );

		$this->view->paginator = $paginator = $table->getPaginator($params);
    if ($paginator->getTotalItemCount()) {
			$empty = false;
		}

    $table = Engine_Api::_()->getDbTable('participants', 'vote');
    $params = array(
      'user_id' => $subject->getIdentity(),
      'sort' => 'newest'
    );

    $this->view->partPaginator = $partPaginator = $table->getPaginator($params);
		if ($partPaginator->getTotalItemCount()) {
			$empty = false;
		}

    if ($empty) {
      return $this->setNoRender();
    }

		$paginator->setItemCountPerPage(20);
    $partPaginator->setItemCountPerPage(40);
    
		if ($this->_getParam('titleCount', false) && $paginator->getTotalItemCount() > 0) {
      $this->_childCount = $paginator->getTotalItemCount();
    }
  }

	public function getChildCount()
  {
    return $this->_childCount;
  }

}